
#delimit;
glo star_level "star(* 0.05 ** 0.01 *** 0.001)";

* Table 1 - Average spectator characteristics by treatment condition;
#delimit;
use "${data}\spectator.dta", replace;
 
bys id: gen n_s = (_n==1);
        gen n_d = 1;

levelsof region   , local(reg); foreach r of local reg {; gen reg_`r' = (region    == "`r'"); };
levelsof hh_income, local(inc); foreach i of local inc {; gen inc_`i' = (hh_income == `i'  ); };

recode hh_income (1/4 = 1) (5/7 = 2) (8= 3) (9 = 4) (10/11 = 5), gen(hh_inc_c);

gen inc_000_040 = (inlist(hh_income,1,2,3,4));
gen inc_040_075 = (inlist(hh_income,5,6,7  ));
gen inc_075_100 = (inlist(hh_income,8      ));
gen inc_100_999 = (inlist(hh_income,9,10,11));

gen age_18_40 = (inrange(age,18,40));
gen age_41_64 = (inrange(age,41,64));
gen age_65_99 = (inrange(age,65,99));

gen college    = (education>=5);

gen     time_tot = time_yourtask + time_aboutworkers + time_comprehension + time_decision + time_effort + time_beliefs;
replace time_tot = time_tot/60;

foreach v in fair_work fair_talent fair_luck fair_connections better_life luck_connections issues_democrat issues_republican redistribute_regardless redistribute_never redistribute_luck income_distribution economic_liberal social_conservative higher_income {; ren `v' tmp; gen `v' = (inrange(tmp,1,2)); drop tmp; };

gen F = .; gen p_F = .;

 gen cf0  = (cf == 1 & info == "no" );
 gen cf1  = (cf == 1 & info == "yes");
 gen ea0  = (ea == 1 & info == "no" );
 gen ea1  = (ea == 1 & info == "yes");
 gen ep0  = (ep == 1 & info == "no" );
 gen ep1  = (ep == 1 & info == "yes");

global vlist age male married children_under18 white black hispanic college total_numeracy working_ft working_pt retired own_house inc_000_040 inc_040_075 inc_075_100 inc_100_999 reg_midwest reg_northeast reg_south reg_west issues_democrat issues_republican fair_work fair_talent fair_luck fair_connections mobile_device time_total passed_att;

gen grp = (condition + info);
encode grp, gen(grp_num);

foreach t in cf0 cf1 ea0 ea1 ep0 ep1 {; 
	qui reghdfe `t' $vlist if n_s == 1, cluster(id); 
	qui test $vlist;

	loc p = Ftail(e(df_m), e(df_r), e(F)); 
	replace F   = e(F) if `t' == 1; 
	replace p_F = `p'  if `t' == 1;
};


preserve; collapse (sum) n_s n_d (mean) $vlist `wt' (p50) time=time_tot; gen condition = "all"; gen info = "all"; tempfile all; save `all', replace; 
restore;  collapse (sum) n_s n_d (mean) $vlist `wt' (p50) time=time_tot, by(condition info); append using `all';


cap replace F = . if condition == "all"; cap replace p_F = . if condition == "all";

replace time_tot = time; drop time;
foreach v in n_s n_d        {; gen temp="&"+string(`v',"%15.0fc"); drop `v'; rename temp `v';};
foreach v in         $vlist {; gen temp="&"+string(`v',"%15.2f" ); drop `v'; rename temp `v';};
foreach v in n_s n_d $vlist {; rename `v' val`v';};

gen tmp = "_"+condition+"_"+info; drop condition info;

reshape long val, i(tmp) j(var) string;
reshape wide val, i(var) j(tmp) string;

gen order=.; local n 1; foreach v in $vlist n_s n_d {; replace order=`n' if var=="`v'"; local ++n;}; sort order; drop order;

gen     cat = "oth" ;
replace cat = "dem" if regex(var,"age") | inlist(var,"male", "married", "children_under18", "white", "black", "hispanic");
replace cat = "edu" if inlist(var,"college", "total_numeracy", "working_pt", "working_ft", "retired", "own_house");
replace cat = "reg" if regex(var,"reg_");
replace cat = "pol" if regex(var,"issues_") | regex(var,"fair_");
replace cat = "inc" if regex(var,"inc_");

gen     label= "";
replace label="Age"                                    if var=="age";
replace label="Male"                                   if var=="male";
replace label="Married"                                if var=="married";
replace label="Nr. of children under 18"               if var=="children_under18";
replace label="White"                                  if var=="white";
replace label="Black"                                  if var=="black";
replace label="Hispanic"                               if var=="hispanic";
												       
replace label="Completed college"                      if var=="college";
replace label="Numeracy index"                         if var=="total_numeracy";
replace label="Works part-time"                        if var=="working_pt";
replace label="Works full-time"                        if var=="working_ft";
replace label="Retired"                                if var=="retired";
replace label="Houseowner"                             if var=="own_house";

replace label="Income below 40k"                      if var=="inc_000_040"; 
replace label="Income btw. 40k and 75k"               if var=="inc_040_075"; 
replace label="Income btw. 75k and 100k"              if var=="inc_075_100"; 
replace label="Income over 100k"                      if var=="inc_100_999"; 
replace label="Income between 100k and 150k"          if var=="inc_100_150"; 
replace label="Income greater than 150k"              if var=="inc_150_999";                       

replace label="Lives in the Midwest"                  if var=="reg_midwest";
replace label="Lives in the Northeast"                if var=="reg_northeast";
replace label="Lives in the South"                    if var=="reg_south";
replace label="Lives in the West"                     if var=="reg_west";
												      
replace label="Democrat"                              if var=="issues_democrat";
replace label="Republican"                            if var=="issues_republican";
replace label="Influence of hard work is fair"        if var=="fair_work";
replace label="Influence of talent is fair"           if var=="fair_talent";
replace label="Influence of luck is fair"             if var=="fair_luck";
replace label="Influence of connections are fair"     if var=="fair_connections";
												      
replace label="Used a mobile device"                  if var=="mobile_device"; 
replace label="Minutes spent in experiment"           if var=="time_total"; 
replace label="Passed attention check"                if var=="passed_att";
replace label="F-statistic"                           if var=="F";
replace label="p-value F-statistic"                   if var=="p_F";
replace label="\(N\) (Spectators)"                    if var=="n_s";
replace label="\(N\) (Redistributive decisions)"      if var=="n_d";

gen end="\\"; replace end="\\\midrule" if var == "passed_att";
drop var; gen b1 = "&"; gen b2 = "&"; 

 order label val_all_all b1 val_CF_no val_EA_no val_EP_no b2 val_CF_yes val_EA_yes  val_EP_yes end; 
*order label val_all_all b1 val_CF_no val_IOP_no            b2 val_CF_yes val_IOP_yes            end; 

levelsof cat, local(grps); foreach g of local grps {;
	preserve; keep if cat=="`g'"; drop cat; outsheet using "${res}/spectator-summ-`g'.tex", replace noquote nonames delimiter(" "); restore;
};



* Table 2 - Fraction redistributed as a function of $\pi$;

* Panel A;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "EP" ;
drop if info      == "yes";

replace pi = pi/100;
eststo clear;
eststo: reg shr_red         if condition == "CF",        robust cluster(id);
eststo: reg shr_red         if condition == "EA",        robust cluster(id); gen cons=1; 
eststo: reg shr_red cf cons                     , nocons robust cluster(id); drop cons;

esttab using "${res}/redist-cons.tex", rename(cf _cons) keep(_cons) coeflabels(_cons "Constant") replace noobs nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&");

esttab using "${res}/redist-N.tex", keep(_cons) drop(_cons) replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));




* Panel B;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "EP";
drop if info      == "yes";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;  // Use 1-pi instead of pi;

eststo clear;
eststo: reg shr_red pi             if condition == "CF",        robust cluster(id);
eststo: reg shr_red pi             if condition == "EA",        robust cluster(id); gen cons=1; rename pi pi0; gen c = cf; gen pi = pi0*cf; 
eststo: reg shr_red pi pi0 cons c                      , nocons robust cluster(id); drop c pi; 

esttab using "${res}/redist-slope.tex", keep(pi _cons) rename(c _cons) coeflabels(pi "Prob.~best~performer~lost~ OPAREN 1 - $\pi$ CPAREN" _cons "Constant") replace nonotes nonumbers noobs nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&");


* Panel C;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "EP";
drop if info      == "yes";

replace pi_bin = 13-pi_bin; // Change to use 1-pi bins;
levelsof pi_bin, local(bins); foreach p of local bins {; gen bin_`p' = (pi_bin == `p'); };

eststo clear;
eststo: reg shr_red bin_* if condition == "CF", nocons robust cluster(id);
eststo: reg shr_red bin_* if condition == "EA", nocons robust cluster(id);


drop bin_*; foreach p of local bins {; gen c_`p'=(pi_bin == `p'); }; 
		    foreach p of local bins {; gen bin_`p' = c_`p'*cf ; };

eststo: reg shr_red c_* bin_*, nocons robust cluster(id); drop bin_*;

esttab using "${res}/redist-bins.tex", keep(bin*) replace nonotes noobs nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&")
coeflabels(
bin_1  "1-$\pi = 0.00$" 
bin_2  "1-$\pi \in (0.00, 0.05]$" 
bin_3  "1-$\pi \in (0.05, 0.10]$" 
bin_4  "1-$\pi \in (0.10, 0.15]$" 
bin_5  "1-$\pi \in (0.15, 0.20]$" 
bin_6  "1-$\pi \in (0.20, 0.25]$" 
bin_7  "1-$\pi \in (0.25, 0.30]$" 
bin_8  "1-$\pi \in (0.30, 0.35]$" 
bin_9  "1-$\pi \in (0.35, 0.40]$" 
bin_10 "1-$\pi \in (0.40, 0.45]$" 
bin_11 "1-$\pi \in (0.45, 0.50)$" 
bin_12 "1-$\pi = 0.50$" _cons "Constant");



* Table 3 - The impact of unequal opportunities on redistribution decisions;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "CF";
drop if condition == "EP";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;   // Use 1-pi instead of pi;

gen has_info = (info == "yes");

eststo clear; 
eststo: reg shr_red diff_m         if has_info ==0, cluster(id); est store model1;
eststo: reg shr_red        ratio_m if has_info ==0, cluster(id); est store model2;
eststo: reg shr_red diff_m ratio_m if has_info ==0, cluster(id); est store model3;
esttab using "${res}/redist-determ.tex", keep(diff_m ratio_m _cons) 
coeflabels(diff_m "Multiplier~difference" ratio_m "Multiplier~ratio" _cons "Constant") replace nonotes nonumbers nomtitles se nolines nogaps noobs b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));


#delimit;
reg shr_red diff_m         if has_info ==0; est store model1;
reg shr_red        ratio_m if has_info ==0; est store model2;
reg shr_red diff_m ratio_m if has_info ==0; est store model3;

suest model1 model3, robust cluster(id); test [model1_mean]diff_m  = [model3_mean]diff_m ;
suest model2 model3, robust cluster(id); test [model2_mean]ratio_m = [model3_mean]ratio_m;

